package controller.api;
import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;

import common.inter.ServicerStationInter;
import common.inter.StaffStationInter;
import model.DaliyRecord;
import model.DaliyRecords;
import service.DaliyRecordService;

public class ApiDaliyRecordController extends BaseApiController {
	@Inject DaliyRecordService daliyRecordService ;

	@Before(ServicerStationInter.class)
	public void list() {
	    Kv kv = getParamKv() ;
	    kv.set("tdr.stationId" , getStation().getId());
	    Integer pageNumber = getParaToInt("pageNumber", 1);
	    Integer pageSize = getParaToInt("pageSize", 10);
	    set("page", daliyRecordService.getApiPage( kv , pageNumber, pageSize));
	    renderJson();
	}
	
	@Before(StaffStationInter.class)
	public void save() {
		DaliyRecord daliyRecord = getModel(DaliyRecord.class , "x");
        Ret ret = daliyRecordService.save(daliyRecord , getStation() , getStaff());
        renderJson(ret);
	}
	
	@Before(StaffStationInter.class)
	public void batchSave() {
		String factors = getPara("factors");
		Integer days = getParaToInt("days" , 7 );
		DaliyRecords daliyRecords = getModel(DaliyRecords.class,"r");
		List<DaliyRecord> list = getModelList(DaliyRecord.class);
		Ret ret = daliyRecordService.batchSave(list , daliyRecords , factors , days , getStation() , getStaff());
		renderJson(ret);
	}
}
